<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - lda_abstract.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2014  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#undef</font> DLIB_LDA_ABSTRACT_Hh_
<font color='#0000FF'>#ifdef</font> DLIB_LDA_ABSTRACT_Hh_

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>map<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='compute_lda_transform'></a>compute_lda_transform</b> <font face='Lucida Console'>(</font>
        matrix<font color='#5555FF'>&lt;</font>T<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> X,
        matrix<font color='#5555FF'>&lt;</font>T,<font color='#979000'>0</font>,<font color='#979000'>1</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> M,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> row_labels,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> lda_dims <font color='#5555FF'>=</font> <font color='#979000'>500</font>,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> extra_pca_dims <font color='#5555FF'>=</font> <font color='#979000'>200</font>
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - X.size() != 0
            - row_labels.size() == X.nr()
            - The number of distinct values in row_labels &gt; 1
            - lda_dims != 0
        ensures
            - We interpret X as a collection X.nr() of input vectors, where each row of X
              is one of the vectors.
            - We interpret row_labels[i] as the label of the vector rowm(X,i).
            - This function performs the dimensionality reducing version of linear
              discriminant analysis.  That is, you give it a set of labeled vectors and it
              returns a linear transform that maps the input vectors into a new space that
              is good for distinguishing between the different classes.  In particular,
              this function finds matrices Z and M such that:
                - Given an input vector x, Z*x-M, is the transformed version of x.  That is,
                  Z*x-M maps x into a space where x vectors that share the same class label
                  are near each other. 
                - Z*x-M results in the transformed vectors having zero expected mean.
                - Z.nr() &lt;= lda_dims
                  (it might be less than lda_dims if there are not enough distinct class
                  labels to support lda_dims dimensions).
                - Z.nc() == X.nc()
                - We overwrite the input matrix X and store Z in it.  Therefore, the
                  outputs of this function are in X and M.
            - In order to deal with very high dimensional inputs, we perform PCA internally
              to map the input vectors into a space of at most lda_dims+extra_pca_dims
              prior to performing LDA.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    std::pair<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <b><a name='equal_error_rate'></a>equal_error_rate</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> low_vals,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> high_vals 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - This function finds a threshold T that best separates the elements of
              low_vals from high_vals by selecting the threshold with equal error rate.  In
              particular, we try to pick a threshold T such that:
                - for all valid i:
                    - high_vals[i] &gt;= T
                - for all valid i:
                    - low_vals[i] &lt; T
              Where the best T is determined such that the fraction of low_vals &gt;= T is the
              same as the fraction of high_vals &lt; T.
            - Let ERR == the equal error rate.  I.e. the fraction of times low_vals &gt;= T
              and high_vals &lt; T.  Note that 0 &lt;= ERR &lt;= 1.
            - returns make_pair(ERR,T) 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='roc_point'></a>roc_point</b>
    <b>{</b>
        <font color='#0000FF'><u>double</u></font> true_positive_rate;
        <font color='#0000FF'><u>double</u></font> false_positive_rate;
        <font color='#0000FF'><u>double</u></font> detection_threshold;
    <b>}</b>;

    std::vector<font color='#5555FF'>&lt;</font>roc_point<font color='#5555FF'>&gt;</font> <b><a name='compute_roc_curve'></a>compute_roc_curve</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> true_detections,
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> false_detections 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - true_detections.size() != 0
            - false_detections.size() != 0
        ensures
            - This function computes the ROC curve (receiver operating characteristic)
              curve of the given data.  Therefore, we interpret true_detections as
              containing detection scores for a bunch of true detections and
              false_detections as detection scores from a bunch of false detections.  A
              perfect detector would always give higher scores to true detections than to
              false detections, resulting in a true positive rate of 1 and a false positive
              rate of 0, for some appropriate detection threshold.
            - Returns an array, ROC, such that:
                - ROC.size() == true_detections.size()+false_detections.size()
                - for all valid i:
                    - If you were to accept all detections with a score &gt;= ROC[i].detection_threshold 
                      then you would obtain a true positive rate of ROC[i].true_positive_rate and a 
                      false positive rate of ROC[i].false_positive_rate.
                - ROC is ordered such that low detection rates come first.  That is, the
                  curve is swept from a high detection threshold to a low threshold.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_LDA_ABSTRACT_Hh_
</font>


</pre></body></html>